package com.crm.miaohe.controller.report;

import com.crm.miaohe.controller.report.response.DashboardResponse;
import com.crm.miaohe.controller.report.response.OrderReportMonth;
import com.crm.miaohe.controller.report.response.OrderReportWeek;
import com.crm.miaohe.controller.report.response.OrderReportYear;
import com.crm.miaohe.service.DashboardService;
import com.crm.miaohe.service.OrderReportService;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/erp/dashboard")
public class DashboardController {
    private final DashboardService dashboardService;

    private final OrderReportService<OrderReportWeek> weekOrderReportService;
    private final OrderReportService<OrderReportMonth> monthOrderReportService;
    private final OrderReportService<OrderReportYear> yearOrderReportService;


    public DashboardController(DashboardService dashboardService,
                               @Qualifier("weekOrderReportService") OrderReportService<OrderReportWeek> weekOrderReportService,
                               @Qualifier("monthOrderReportService") OrderReportService<OrderReportMonth> monthOrderReportService,
                               @Qualifier("yearOrderReportService") OrderReportService<OrderReportYear> yearOrderReportService) {
        this.dashboardService = dashboardService;
        this.weekOrderReportService = weekOrderReportService;
        this.monthOrderReportService = monthOrderReportService;
        this.yearOrderReportService = yearOrderReportService;
    }

    @GetMapping
    public ResponseEntity<DashboardResponse> dashboardData() {
        return ResponseEntity.ok(dashboardService.getDashboardData());
    }

    @GetMapping("/orderReport/week")
    public ResponseEntity<OrderReportWeek> weekHistory() {
        return ResponseEntity.ok(weekOrderReportService.orderReport());
    }

    @GetMapping("/orderReport/month")
    public ResponseEntity<OrderReportMonth> monthHistory() {
        return ResponseEntity.ok(monthOrderReportService.orderReport());
    }

    @GetMapping("/orderReport/year")
    public ResponseEntity<OrderReportYear> yearHistory() {
        return ResponseEntity.ok(yearOrderReportService.orderReport());
    }
}
